<template>
        <!-- 列表页面 -->
        <div class="container" v-if="!showEdit">
            <div class="header">
                <div class="title plus">
                    <span>学历认证</span>
                </div>
            </div>
            <!-- 表格 -->
            <el-table
                border
                v-loading="loading"
                :data="tableData"
                stripe>
              <el-table-column
                  :show-overflow-tooltip="true"
                  prop="verification_code"
                  label="学信网在线验证码"
              >
              </el-table-column>
                <el-table-column
                  :show-overflow-tooltip="true"
                  prop="status_name"
                  label="审核状态"
                  width="100"
                  >
                </el-table-column>
                <el-table-column
                  :show-overflow-tooltip="true"
                  prop="update_time"
                  label="申请时间"
                >
                </el-table-column>
                <el-table-column label="操作" fixed="right" width="170">
                    <template slot-scope="scope">
                      <template v-for="(item,index) in operate">
                        <el-button
                            :key="index"
                            :type="item.type"
                            plain
                            size="mini"
                            @click.native.prevent.stop="buttonMethods(item.func, scope.$index, scope.row)"
                            v-if="scope.row.status != 2"
                        >{{item.name}}</el-button>
                      </template>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <!-- 编辑页面 -->
        <education-edit v-else-if="showEdit" @editClose="editClose" :UserEducationId="UserEducationId"></education-edit>
</template>
<script>
import auth from '@/models/auth'
import EducationEdit from './EducationEdit'

export default {
  components: { EducationEdit },
  data() {
    return {
      tableData: [],
      operate: [],
      loading: false,
      showEdit: false,
      UserEducationId: 0,
      // 分页相关
      refreshPagination: true, // 页数增加的时候，因为缓存的缘故，需要刷新Pagination组件
      currentPage: 1, // 默认获取第一页的数据
      pageCount: 10, // 每页10条数据
      total_nums: 0, // 分组内的总数
    }
  },
  created() {
    this.loading = true
    this._getTableData(this.currentPage, this.pageCount)
    this.operate = [
      { name: '审核操作', func: 'handleEdit', type: 'primary' },
    ]
  },
  methods: {
    // 获取数据
    async _getTableData(start, count) {
      const res = await auth.getEducationList(start, count, {})
      this.tableData = res.data
      this.total_nums = res.count
      this.$nextTick(() => {
        this.loading = false
      })
    },
    // 操作列
    buttonMethods(func, index, row) {
      const self = this
      const { methods } = this.$options
      methods[func](self, index, row)
    },
    handleEdit(self, index, val) {
      // eslint-disable-next-line no-param-reassign
      self.UserEducationId = val.id
      // eslint-disable-next-line no-param-reassign
      self.showEdit = true
    },
    editClose() {
      this.showEdit = false
      this._getTableData(this.currentPage, this.pageCount)
    },
  },
}
</script>

<style lang="scss" scoped>
    .container {
        padding: 0 30px;
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;

            .title {
                height: 59px;
                line-height: 59px;
                color: $parent-title-color;
                font-size: 16px;
                font-weight: 500;
            }
        }
        .pagination {
            display: flex;
            justify-content: flex-end;
            margin: 20px;
        }
    }
</style>
